package com.example.aircraftticketingsystemserver.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.aircraftticketingsystemserver.entity.Flight;
import com.example.aircraftticketingsystemserver.entity.Timezone;
import com.example.aircraftticketingsystemserver.mapper.TimezoneMapper;
import com.example.aircraftticketingsystemserver.service.ITimezoneService;
import com.example.aircraftticketingsystemserver.utils.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class TimezoneServiceImpl extends ServiceImpl<TimezoneMapper, Timezone> implements ITimezoneService {
    @Resource
    TimezoneMapper timezoneMapper;
    @Override
    public Page getFlightsWithLocalTime(Integer pageNo, Integer pageSize) {
        Page page=new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<Flight> flights=timezoneMapper.selectFlightsWithLocalTime();
        flights.forEach(System.out::println);
        PageInfo<Flight> info = new PageInfo<>(flights);
        page.setPage(info.getList());
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setHasNext(info.isHasNextPage());
        page.setHasPre(info.isHasPreviousPage());
        page.setTotal(info.getTotal());
        page.setPageCount(info.getPages());
        return page;
    }

    @Override
    public void addCity(Timezone timezone) {
        timezoneMapper.addCity(timezone);
    }

    @Override
    public void deleteCity(Integer cityId) {
        timezoneMapper.deleteCity(cityId);
    }

    @Override
    public void batchDeleteCity(List<Integer> cityIds) {
        timezoneMapper.batchDeleteCity(cityIds);
    }

    @Override
    public void updateCity(Timezone timezone) {
        timezoneMapper.updateCity(timezone);
    }

    @Override
    public Page getCityByParams(Integer pageNo, Integer pageSize, String city, String timezoneId) {
        Page page=new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<Timezone> cities =timezoneMapper.getCityByParams(city, timezoneId);
        PageInfo<Timezone> info=new PageInfo<>(cities);
        page.setPage(info.getList());
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setHasNext(info.isHasNextPage());
        page.setHasPre(info.isHasPreviousPage());
        page.setTotal(info.getTotal());
        page.setPageCount(info.getPages());
        return page;
    }

    @Override
    public List<Timezone> getCityList(String city, String timezoneId) {
        return timezoneMapper.getCityByParams(city, timezoneId);
    }
}
